package com.fs.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.entity.*;
import com.fs.mapper.MaterialattachmentsMapper;
import com.fs.mapper.MaterialcategoryMapper;
import com.fs.service.IMaterialcategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-06-12
 */
@Service
public class MaterialcategoryServiceImpl  implements IMaterialcategoryService {
    @Autowired
    MaterialcategoryMapper materialcategoryMapper;
    @Autowired
    MaterialattachmentsMapper materialattachmentsMapper;
    @Override
    public List<Materialcategory> getKind(int mckind) {
        List<Materialcategory> materialcategories = materialcategoryMapper.selectByMckind(mckind);
        return materialcategories;
    }
    @Override
    public Page queryByPageAndCondition(MaterCategoryCondition materCategoryCondition) {
        Page<MaterialcategoryShow> page=Page.of(1,2);
        if(materCategoryCondition.getCurrentpage()!=null)
        {
            page.setCurrent(materCategoryCondition.getCurrentpage());
        }
        Page<MaterialcategoryShow> matPage=materialcategoryMapper.selectMaterialcategoryShowPageWithConditions(page,materCategoryCondition);
        return matPage;
    }

    @Override
    public Boolean updateMaterCategory(Materialcategory materialcategory) {

        QueryWrapper<Materialcategory> queryWrapper=new QueryWrapper();
        queryWrapper.eq("mcid",materialcategory.getMcid());
        int rs=materialcategoryMapper.update(materialcategory,queryWrapper);
        if(rs!=0)
        {
            return true;
        }
        return false;
    }
    @Override
    public boolean AddMaterCategory(Materialcategory materialcategory) {

        int rs = materialcategoryMapper.insert(materialcategory);
        if(rs!=0)
        {

            return true;
        }
        return false;
    }
}
